﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QLKDS.DTO;

namespace QLKDS.DAL
{
    public class DisciplineManager
    {
        public DisciplineInfo GetDisciplineById(int id)
        {
            using (var db = new QLKDSDataContext())
            {
                var queryDiscipline = from d in db.Disciplines
                                    where d.Id.Equals(id)
                                    select new DisciplineInfo { Id = d.Id,EmployeeId=d.EmployeeId,Reason=d.Reason,Method=d.Method};

                return queryDiscipline.First();
            }
        
        }


        public IList<DisciplineInfo> ListDiscipline()
        {
            using (var db = new QLKDSDataContext())
            {
                var queryDiscipline = from d in db.Disciplines
                                      select new DisciplineInfo { Id = d.Id, EmployeeId = d.EmployeeId, Reason = d.Reason, Method = d.Method };

                return queryDiscipline.ToList();
            }
        }
    

        public void CreateDiscipline(Discipline Discipline)
        {
            using (var db = new QLKDSDataContext())
            {
                db.Disciplines.InsertOnSubmit(Discipline);

                db.SubmitChanges();
               
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="Discipline"></param>
        public void UpdateDiscipline(Discipline Discipline)
        {
            using (var db = new QLKDSDataContext())
            {
                var _Discipline = db.Disciplines.Single(d => d.Id.Equals(Discipline.Id));

                _Discipline.Reason = Discipline.Reason;
                _Discipline.Method = Discipline.Method;
                _Discipline.Description = Discipline.Description;
                db.SubmitChanges();
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        public void DeleteDiscipline(int id)
        {
            using (var db = new QLKDSDataContext())
            {
                var _Discipline = db.Disciplines.Single(d => d.Id.Equals(id));

                db.Disciplines.DeleteOnSubmit(_Discipline);
                db.SubmitChanges();
            }
        }

     
    }
}
